//---------------------------------------------------------------------------
// Name:	CMeteor.h
// Desc:	Header of CMeteor
// Author:	D.C
// Date:	2007-9-19 10:03:11
//---------------------------------------------------------------------------

#ifndef _C_Meteor_H_	
#define _C_Meteor_H_

#include <e32std.h>
#include <in_sock.h>

#include <es_sock.h>
#include <commdb.h>
#include "iapmgr.h"
#include <commdbconnpref.h>

#define KReadBufferSize             (1024 * 64)
//---------------------------------------------------------------------------
//CMeteor
//---------------------------------------------------------------------------
enum TMeteorFlag
{
	TDF_NotConnected, TDF_Connected, TDF_DNSReady, TDF_SocketOpened, TDF_DataWriteOver, TDF_DataReading, TDF_DataReadOver
};
struct MMeteorNotifier
{
	virtual void ConnectionComplete(TInt aCode) = 0;
	virtual void DNSComplete(TInt aCode) = 0;
	virtual void SocketOpenComplete(TInt aCode) = 0;
	virtual void WriteBufferComplete(TInt aCode) = 0;
	virtual void ReadBufferComplete(TInt aCode,const TDesC8& aBuf) = 0;
	virtual void UnknowComplete(TInt aCode) = 0;
};

class CMeteor:public CActive
{
private:
	enum TMeteorState
	{
		TMeteorNotConnected, TMeteorConnStarting, TMeteorHostLookingUp, TMeteorHostLookUpDone, TMeteorSocketConnecting, TMeteorSocketConnectedAndIdle, TMeteorWriting, TMeteorReading
	};
public:
	static CMeteor* NewL(MMeteorNotifier* aNotifier);
	void ConstructL(MMeteorNotifier* aNotifier);
	CMeteor();
	~CMeteor();
public:
	TInt Connect(const TDesC& aHost,TInt aPort,TUint32 aIAP);
	void Disconnect();
	TInt OpenSocket();
	void CloseSocket();
	TInt Read();
	TInt Write(const TDesC8& aBuf);
	TBool ProxyUsed();
private:
	void DoCancel();
	void RunL();
	TInt RunError(TInt aError);
private:
	MMeteorNotifier* m_pNotifier;
	TUint32 m_iIAP;
	TBuf<KCommsDbSvrMaxFieldLength>m_tProxyHost;
	TUint32 m_iProxyPort;
	HBufC* m_pServerHost;
	TUint32 m_iServerPort;
	TBuf8<KReadBufferSize>m_tReadBuffer;
	HBufC8* m_pHdr;

	RConnection m_rConnection;
	TCommDbConnPref m_tPref;

	RSocketServ m_rSocketServ;
	RHostResolver m_rResolver;
	RSocket m_rSocket;
	TNameEntry m_tNameEntry;
	TUint32 m_u32Addr;
	TMeteorState m_tStatus;
	TSockXfrLength m_tNatrueSize;
	TBool m_bIsWorking;
	TBool m_bProxyUsed;
	TBool m_bIsGRPS;
};

#endif //_C_Meteor_H_
